public class Leet240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int i = 0, j = matrix[0].length-1;
        while (true){
            if (matrix[i][j]==target)
                return true;
            else if (matrix[i][j]<target){
                if (i<matrix.length-1)
                    i++;
                else break;
            }else {
                if (j>0)
                    j--;
                else break;
            }
        }
        return false;
    }
}
